package com.ruoyi.main.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.main.domain.MainPost;
import com.ruoyi.main.service.IMainPostService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 岗位管理Controller
 * 
 * @author chao
 * @date 2024-07-23
 */
@Controller
@RequestMapping("/main/post")
public class MainPostController extends BaseController
{
    private String prefix = "main/post";

    @Autowired
    private IMainPostService mainPostService;

    @RequiresPermissions("main:post:view")
    @GetMapping()
    public String post()
    {
        return prefix + "/post";
    }

    /**
     * 查询岗位管理列表
     */
    @RequiresPermissions("main:post:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MainPost mainPost)
    {
        startPage();
        List<MainPost> list = mainPostService.selectMainPostList(mainPost);
        return getDataTable(list);
    }

    /**
     * 导出岗位管理列表
     */
    @RequiresPermissions("main:post:export")
    @Log(title = "岗位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MainPost mainPost)
    {
        List<MainPost> list = mainPostService.selectMainPostList(mainPost);
        ExcelUtil<MainPost> util = new ExcelUtil<MainPost>(MainPost.class);
        return util.exportExcel(list, "岗位管理数据");
    }

    /**
     * 新增岗位管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存岗位管理
     */
    @RequiresPermissions("main:post:add")
    @Log(title = "岗位管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MainPost mainPost)
    {
        return toAjax(mainPostService.insertMainPost(mainPost));
    }

    /**
     * 修改岗位管理
     */
    @RequiresPermissions("main:post:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MainPost mainPost = mainPostService.selectMainPostById(id);
        mmap.put("mainPost", mainPost);
        return prefix + "/edit";
    }

    /**
     * 修改保存岗位管理
     */
    @RequiresPermissions("main:post:edit")
    @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MainPost mainPost)
    {
        return toAjax(mainPostService.updateMainPost(mainPost));
    }

    /**
     * 删除岗位管理
     */
    @RequiresPermissions("main:post:remove")
    @Log(title = "岗位管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mainPostService.deleteMainPostByIds(ids));
    }
}
